<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>邮件列表</title>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/iCheck/custom.css}" rel="stylesheet">
    <link th:href="@{/css/animate.css}" rel="stylesheet">
    <link th:href="@{/css/style.css}" rel="stylesheet">
    <link th:href="#{/css/iCheck/custom.css}" rel="stylesheet">
    <style type="text/css">
        #bootstrap-table {border-left: 0px; border-right:0px}
        #bootstrap-table th{border-left: 0px; border-right: 0px}
        #bootstrap-table td{border-left: 0px; border-right: 0px}
    </style>
</head>

<body>

    <div id="wrapper">
        <div class="wrapper wrapper-content gray-bg">
        <div class="row">
            <th:block th:include="include :: emailNavPage" />
            <div class="col-lg-9 animated fadeInRight">
            <div class="mail-box-header">
                <form  class="pull-right mail-search select-list" id="formId">
                    <div class="input-group">
                        <input type="hidden" name="mailSearchType" th:value="${mailType}" id="mailType" >
                        <input type="text" class="form-control input-sm" name="emailSubject"  placeholder="Search email">
                        <div class="input-group-btn">
                            <a onclick="$.table.search()" class="btn btn-sm btn-primary">
                                请输入邮件主题
                            </a>
                        </div>
                    </div>
                </form>
                <h2>
                    Ding-Flow邮件列表
                </h2>

                <span id="systemUserId" hidden>
                    <shiro:principal property='userId'/>
                </span>
               <div class="mail-tools tooltip-demo m-t-md">
<!--                    <button th:if="${mailType eq  4}" class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="left" title="删除" onclick="markDelete()"><i class="fa fa-remove"></i></button>-->
                    <button th:if="${mailType eq  6||mailType eq  3}" class="btn btn-success btn-sm" data-toggle="tooltip" data-placement="top" title="标记为已读" onclick="markRead()"><i class="fa fa-eye"></i> </button>
<!--                    <button th:if="${mailType eq  6||mailType eq  7}" class="btn btn-warning btn-sm" data-toggle="tooltip" data-placement="top" title="标记为重要邮件" onclick="remarkImportant()"><i class="fa fa-star"></i> </button>
                    <button th:if="${mailType eq  6||mailType eq  3 ||mailType eq  1}" class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="移到垃圾箱" onclick="remarkTrash()"><i class="fa fa-trash-o"></i> </button>-->

                </div>
            </div>
                <div class="mail-box">
                <table  id="bootstrap-table" class="table table-hover table-mail table-no-borde">
                </table>
                </div>
            </div>
        </div>
        </div>
        </div>

    <!-- Mainly scripts -->
    <script th:src="@{/js/jquery.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>
    <script th:src="@{/js/plugins/slimscroll/jquery.slimscroll.min.js}"></script>
    <script th:src="@{/js/plugins/pace/pace.min.js}"></script>
    <script th:src="@{/ajax/libs/iCheck/icheck.min.js}"></script>
    <script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
    <script th:src="@{/ajax/libs/layui/layui.js}"></script>
    <script th:src="@{/ruoyi/js/common.js}"></script>
    <script th:src="@{/ruoyi/js/ry-ui.js}"></script>
    <script th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
    <script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js?v=20200727}"></script>
    <script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js?v=20200727}"></script>
    <script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js?v=20200727}"></script>
    <!--<th:block th:include="include :: footer" />-->
    <script>
        var prefix =  "/system/email";
        $(document).ready(function(){
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green'
            });

            $.get(prefix+"/getSysOaEmailData", function(data) {
                if (data.code == web_status.SUCCESS ) {
                    var sysOaEmailData=data.data;
                    $("#readTotal").text(sysOaEmailData.readTotal);
                    $("#draftsTotal").text(sysOaEmailData.draftsTotal);
                }  else if (data.code == web_status.WARNING) {
                    $.modal.alertWarning(data.msg)
                }  else {
                    $.modal.alertError(data.msg);
                }
            });
        });

        var options = {
            url: prefix + "/getMyList",
            rememberSelected: true,
            modalName: "邮件",
            showToggle:false,
            showHeader:false,
            showSearch:false,
            showRefresh:false,
            showColumns:false,
            queryParams: queryParams,
            striped:true,
            height:'30px',
            columns: [{
                field: 'state',
                checkbox: true,
                visible : visible(),
                formatter: function(value, row, index) {
                    var messageReadStatus=row.messageReadStatus;
                    var mailType= $("#mailType").val();
                  if(mailType==6){
                      if(messageReadStatus==0){
                          return { disabled : false}
                      }else {
                          return { disabled : true}
                      }
                  }else {
                      return {visible: false}
                  }

                }
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },

                {
                    field: 'emailSubject',
                    title: '邮件主题',
                    align:'left',
                    formatter: function(value, row, index) {
                        var emailStatus= row.emailStatus;
                        if(emailStatus==3){
                            return '<i class="fa fa-flag danger" style="color: red"></i> '+'<a href="javascript:void(0)" onclick="mailDetail(\''+row.id+'\')">'+value+'</a> ';
                        }else {
                            return '<a href="javascript:void(0)" onclick="mailDetail(\''+row.id+'\')">'+value+'</a> ';
                        }


                    }
                },
                {
                    field: 'messageReadStatus',
                    title: '是否已读',
                    width: 30,
                    align:'left',
                    formatter: function(value, row, index) {
                        //from 等于当前用户，并且状态为0代表是发件箱
                        if(value==0){
                            return '<span class="label label-warning pull-right">未读</span>';
                        }else {
                            return '<span class="label label-success pull-right">已读</span>';
                        }
                    }
                },
                {
                    field: 'sendTime',
                    title: '发送时间',
                    width: 220,
                    align: 'right'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];

                        var mailType= $("#mailType").val();
                        var messageReadStatus=row.messageReadStatus;
                        var emailStatus=row.emailStatus;

                        //收件箱
                       /* if((mailType==6|| mailType ==  3)&&messageReadStatus==0){

                            actions.push('<button class="btn btn-success btn-sm" data-toggle="tooltip" data-placement="top" title="标记为已读" onclick="markRead('+row.id+')"><i class="fa fa-eye"></i> </button> ');
                        }*/

                        if((mailType==6|| mailType ==  7)&&emailStatus!=3){
                            actions.push('<button class="btn btn-primary btn-sm" data-toggle="tooltip" data-placement="top" title="标记为重要邮件" onclick="remarkImportant(\''+row.id+'\')"><i class="fa fa-flag"></i> </button> ');
                        }
                        if((mailType==3|| mailType ==  6||mailType==1)&&emailStatus!=4){
                            actions.push('<button class="btn btn-warning btn-sm" data-toggle="tooltip" data-placement="top" title="移到垃圾箱" onclick="remarkTrash(\''+row.id+'\')"><i class="fa fa-trash"></i> </button> ');
                        }
                        if(mailType==4){
                            actions.push('<button class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="删除" onclick="markDelete(\''+row.id+'\')"><i class="fa fa-remove"></i> </button> ');
                        }
                        if(row.emailStatus==1){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="emailEdit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        }

                        return actions.join('');
                    }
                }
                ]
        };
        $.table.init(options);
        function queryParams(params) {
            var search = $.table.queryParams(params);
            return search;
        }

        function visible() {
            var mailType= $("#mailType").val();
            if(mailType==6){
                return true;
            }else {
                return false;
            }

        }
        // 选中数据
        function markRead(){
            var arrays = $.table.selectColumns("id");
            if($.common.isEmpty(arrays)){
                $.modal.msgWarning("请至少选择一条记录");
                return false;
            }
            var config = {
                url: prefix + "/remarkRead",
                type: "post",
                dataType: "json",
                data: {
                    "ids":arrays.join()
                },
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function(result) {
                    if (typeof callback == "function") {
                        callback(result);
                    }
                    if (result.code == web_status.SUCCESS) {
                        $.modal.msg("标记已读成功", modal_status.SUCCESS);
                        setTimeout(function(){
                            window.location.href="#";
                        },3000);
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    }  else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                    $.modal.enable();
                }
            };
            $.ajax(config);
        }

        function remarkImportant(id){
          /*  var arrays = $.table.selectColumns("id");
            if($.common.isEmpty(arrays)){
                $.modal.msgWarning("请至少选择一条记录");
                return false;
            }*/
            var config = {
                url: prefix + "/remarkImportant",
                type: "post",
                dataType: "json",
                data: {
                    "ids":id
                },
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function(result) {
                    if (typeof callback == "function") {
                        callback(result);
                    }
                    if (result.code == web_status.SUCCESS) {
                        $.modal.msg("标记成功，即将跳转到重要邮件箱", modal_status.SUCCESS);
                        setTimeout(function(){
                            window.location.href="/system/email/mailbox/3";
                        },3000);
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    }  else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                    $.modal.enable();
                }
            };
            $.ajax(config)
        }

        function remarkTrash(id){
          /*  var arrays = $.table.selectColumns("id");
            if($.common.isEmpty(arrays)){
                $.modal.msgWarning("请至少选择一条记录");
                return false;
            }*/
            var config = {
                url: prefix + "/remarkTrash",
                type: "post",
                dataType: "json",
                data: {
                    "ids":id
                },
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function(result) {
                    if (typeof callback == "function") {
                        callback(result);
                    }
                    if (result.code == web_status.SUCCESS) {
                        $.modal.msg("标记成功，即将跳转到垃圾箱", modal_status.SUCCESS);
                        setTimeout(function(){
                            window.location.href="/system/email/mailbox/4";
                        },3000);
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    }  else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                    $.modal.enable();
                }
            };
            $.ajax(config);
        }

        function markDelete(id){
          /*  var arrays = $.table.selectColumns("id");
            if($.common.isEmpty(arrays)){
                $.modal.msgWarning("请至少选择一条记录");
                return false;
            }*/
            var config = {
                url: prefix + "/markDelete",
                type: "post",
                dataType: "json",
                data: {
                    "ids":id
                },
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function(result) {
                    if (typeof callback == "function") {
                        callback(result);
                    }
                    if (result.code == web_status.SUCCESS) {
                        $.modal.msg("删除成功，即将跳转到收件箱", modal_status.SUCCESS);
                        setTimeout(function(){
                            window.location.href="/system/email/mailbox/6";
                        },3000);
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    }  else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                    $.modal.enable();
                }
            };
            $.ajax(config)
        }

        function mailDetail(id) {
            var detailUrl="/system/email/mailDetail/"+id;
            $.modal.openTab("查阅邮件", detailUrl);
        }

        function emailEdit(id) {
            window.location.href="/system/email/edit/"+id;
        }


    /*     function getIsRead(outsideId){
            var data;
            $.ajax({
                url: prefix + "/getEmailIsRead/"+outsideId,
                type: "get",
                async: false,
                dataType: "json",
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        data=result.data;
                    }
                }
            });
            return data;
        }*/
    </script>
</body>

</html>
